package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.decorator.CheckedBagDecorator
import com.kemai.designmode.decorator.ReinforceBagDecorator
import com.kemai.designmode.decorator.SpeedDecorator
import com.kemai.designmode.entry.Bag
import com.kemai.designmode.entry.Fruit
import com.kemai.designmode.factory.abstract.AbstractFactory
import com.kemai.designmode.factory.abstract.AppleAbstractFactory
import com.kemai.designmode.factory.abstract.BananaAbstractFactory
import com.kemai.designmode.factory.abstract.OrangeAbstractFactory
//装饰器模式(对某个功能进行装饰，增强功能)
class DecoratorActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("打包苹果","打包香蕉","打包桔子")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("装饰器模式")
        setAdapterContent(studyContent,AbstractFactoryActivity@this,AbstractFactoryActivity@this)
    }

    override fun itemClick(position: Int) {
        var factory: AbstractFactory? = null
        var fruit: Fruit? = null
        var bag: Bag? = null
        when(position){
           0->{
               factory = AppleAbstractFactory()

           }
            1->{
                factory = BananaAbstractFactory()

            }
            2->{
                factory = OrangeAbstractFactory()

            }

        }
        fruit = factory?.getFruit()
        fruit?.draw()
        bag = factory?.getBag()
        bag = CheckedBagDecorator(bag!!)
        bag = ReinforceBagDecorator(bag!!)
        bag = SpeedDecorator(bag!!)
        bag?.pack()

    }

}